<?php

namespace App\Common\Librarys;

class Str
{
    /**
     * @return string
     */
    public static function randomPhone(): string
    {
        $tel_arr = array(
            '130','131','132','133','134','135','136','137','138','139','144','147','150','151','152','153','155','156','157','158','159','176','177','178','180','181','182','183','184','185','186','187','188','189',
        );
        return $tel_arr[array_rand($tel_arr)].mt_rand(1000,9999).mt_rand(1000,9999);
    }

    /**
     * 生成某个范围内的随机时间
     * @param $beginTime
     * @param $endTime
     * @param $is
     * @return false|int|string
     */
    public static function randomDate($beginTime, $endTime="", $is = true) {
        $begin = strtotime($beginTime);
        $end = $endTime == "" ? mktime() : strtotime($endTime);
        $timestamp = rand($begin, $end);
        return $is ? date("Y-m-d H:i:s", $timestamp) : $timestamp;
    }
}